package com.superteam.zzl.view.fragment;


import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.superteam.zzl.activity.databinding.ActivityMainBinding;

/**
 * Created by zhang on 2017/1/6.
 */

/**
 * Fragment 基类
 *  初始化布局
 *  初始化数据
 */

public abstract class BaseFragment extends Fragment{

    public Activity mActivity;
    private ActivityMainBinding amb;

    //Fragment被创建
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mActivity = getActivity();//获取所挂载的Activity
    }

    /**
     * 初始化Fragment布局
     * @param inflater
     * @param container
     * @param savedInstanceState
     * @return
     */
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(initView(),null);
        return view;
    }

    /**
     * Activity创建结束，初始化数据
     * @param savedInstanceState
     */
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initData();
    }

    /**
     * 初始化布局, 子类必须实现
     */
    public abstract int initView();

    /**
     * 初始化数据, 子类可以不实现
     */
    public void initData() {
    }
}
